package com.iaas.test;

import com.myFwk.AuthorizeationApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Title:
 * @Description:
 * @Author: guowl
 * @version： 1.0
 * @Date:2021/10/30
 * @Copyright: Copyright(c)2021 RedaFlight.com All Rights Reserved
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {AuthorizeationApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
public class test1 {
    @Autowired
    private PasswordEncoder passwordEncoder;

    public static void main(String[] args) {

        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

        boolean matches = passwordEncoder.matches("123456", "$2a$10$x/amh0Rpj1KZu9mwyX3MWu9xYiFv2PXv9zzPJWDEHaoxB/6sIClri");
        System.out.println(matches);
    }

    @Test
    public void test2() {
        String encode = passwordEncoder.encode("123456");
        System.out.println(encode);
        log.info("encode code :{}",encode);

    }

    @Test
    public void test3() {
        String hashpw = BCrypt.hashpw("123456", BCrypt.gensalt());
        System.out.println(hashpw);
        log.info("encode code :{}", hashpw);
        boolean checkpw = BCrypt.checkpw("123456", hashpw);
        System.out.println(checkpw);

    }

}
